package system

import (
	"MoSkeleton/framework/core/consts"
	"MoSkeleton/framework/core/motypes"
	"MoSkeleton/framework/mo_gin"
	"MoSkeleton/framework/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type SysAuthService struct {
}

func (s *SysAuthService) Logout(c *gin.Context) error {
	authType, typeExists := c.Get(consts.GinContext_AuthType_Key)
	token, tokenExists := c.Get(consts.GinContext_Token_Key)

	if typeExists && tokenExists {
		claims := utils.GetClaimsFromGin(c)
		expiresAt := motypes.MoTime{Time: claims.ExpiresAt.Time}
		return blackTokenService.AddBlackToken(claims, token.(string), consts.TokenTypeMap[authType.(string)], expiresAt)
	}
	mo_gin.MoLogger.Debug("登出失败", zap.Any("authType", authType), zap.Any("token", token))
	return nil
}
